package com.whfp.afs330h_sdk.utils;

import com.clj.fastble.BleManager;
import com.clj.fastble.callback.BleGattCallback;
import com.clj.fastble.data.BleDevice;

import java.util.List;
import java.util.logging.Handler;

/**
 * BLE工具类
 */
public class BleUtils {
    private Handler handler;
    private BleGattCallback bleGattCallback;

    public Handler getHandler() {
        return handler;
    }

    public void setHandler(Handler handler) {
        this.handler = handler;
    }

    public BleGattCallback getBleGattCallback() {
        return bleGattCallback;
    }

    public void setBleGattCallback(BleGattCallback bleGattCallback) {
        this.bleGattCallback = bleGattCallback;
    }

    /**
     * 判断当前是有设备连接，如果有就返回当前已连接设备，没有就返回null
     */
    public static BleDevice getCurrentDevice() {
        List<BleDevice> bleDevices = BleManager.getInstance().getAllConnectedDevice();
        if (bleDevices != null && bleDevices.size() > 0) {
            return bleDevices.get(0);
        } else {
            return null;
        }
    }
}
